/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lt.ntec.danblog.server.core.model.objectify;

import com.googlecode.objectify.Key;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.persistence.Id;
import javax.persistence.Transient;
import lt.ntec.danblog.server.core.model.Tag;
import lt.ntec.danblog.server.core.model.Taggable;

/**
 *
 * @author Tadas
 */
class ObjectifyTag implements Tag, Comparable<Tag> {
    private String value;

    @Transient
    private Set<? extends Taggable> entrylist;

    @Transient
    private List<Taggable> parents = new ArrayList<Taggable>();

    private List<Key<Taggable>> parentKeys = new ArrayList<Key<Taggable>>();

    @Id
    private Long id;

    public ObjectifyTag(String value, Taggable parent) {
        this.value = value;
        this.parents.add(parent);
        this.parentKeys.add(new Key<Taggable>(parent.getClass(), parent.getId()));
    }



    @Override
    public String getValue() {
        return value;
    }

    @Override
    public Set<? extends Taggable> getEntryList() {
        return entrylist;
    }

    @Override
    public void addParent(Taggable entity) {
        parents.add(entity);
    }

    @Override
    public void removeParent(Taggable entity) {
        parents.remove(entity);
    }

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public int compareTo(Tag o) {
        return o.getValue().compareTo(this.getValue()) * (-1);
    }

    public List<Key<Taggable>> getParentKeys(){
        return parentKeys;
    }

}
